package gui;
import java.util.Scanner;
import java.util.InputMismatchException;

import customers.Customer;
import database.DatabaseManager;

public class Menu
{
	public static void main(String[] args)
	{
		short choice;
		Scanner in;
		
		
		while ( true )
		{
			System.out.println("\n\n\n");
			System.out.println("\t**************************\n");
			System.out.println("\t**************************\n");
			System.out.println("\t******* Main Menu ********\n");
			System.out.println("\t**************************\n");
			System.out.println("\t**************************\n");
			System.out.println("\t 1. New Customer\n");
			System.out.println("\t 2. Existing customer\n");
			System.out.println("\t 3. Exit\n");
			System.out.print("\n\t Enter you choice->");
			
		
		
			in = new Scanner(System.in);
			
			try
			{
				choice = (short)in.nextInt();
				
				System.out.println();
				 if ( !( choice > 0 && choice < 4) )
	         	 {
	           		 System.out.println( "\t Unexpected input, program terminted!!!") ;
	            	 System.exit(1); 
             	 } 
        		
		
				switch (choice)
				{
					case 1: newCustomer(); break;
					case 2: existingCustomer(); break;
					case 3: return;
				}//end of switch loop
			 }
			 catch (InputMismatchException ex)
			 {
				 System.out.println("\tInvalid Input, program terminated!!!");
				 System.exit(1);
			  }// end of try, catch.
		  }//end of while
	  }//end of main 
	
	
	// new Customer menu
	private static void newCustomer()
	{
		System.out.println("\n\n\n");
		System.out.println("\t**************************\n");
		System.out.println("\t**************************\n");
		System.out.println("\t***** Customer deatils****\n");
		System.out.println("\t**************************\n");
		System.out.println("\t**************************\n");
	
	 // temporay vairable that store customer information			
	 // create a new customer.
	 
	 
	 Customer customer = new Customer( );
	 customer.addCustRecord();
	 customer.reservationMenu();
	
	}//end of newCustomer() function.
	
	
	private static void existingCustomer() 
	{
		 short choice;
		 String userName;
		 String password;
		 Boolean flag = null;
     	 Scanner in;
     	
     	 in = new Scanner(System.in);  
     	 System.out.print("\t Enter your user name-> ");
     	 userName = in.next();                        
     	                                                     
     	 System.out.print("\t Enter your Password-> "); 
     	 password = in.next();                        
     	                                                           
         Customer customer = new Customer(userName,password);
         
         flag = customer.checkAuthority( );
        
        
         
        if ( flag.booleanValue())
        {
			//ask for choice whether to book new seat , modify or delete.
			customer.reservationMenu();	
		} //end of if statement	
    	else
    			System.out.println("\t Error:: incorrect username or password");
	}
}                                  